package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.activity.ActivitySearchAllGod;
import nero.yncc.com.createart.bean.BeanCategory;
import nero.yncc.com.createart.custom.MyRecyclerView;
import nero.yncc.com.createart.utils.ImageUtils;

import static nero.yncc.com.createart.base.Constants.IMAGE_HOST;


/**
 * Created by Administrator.
 * Time:2017/3/9 17:41.
 */

public class AdapterCategoryRightBox extends BaseAdapter {

    private ArrayList<BeanCategory> data;
    private Context context;

    public AdapterCategoryRightBox(ArrayList<BeanCategory> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if(view==null){
            view=LayoutInflater.from(context).inflate(R.layout.adapter_category_right,null);
            holder=new Holder(view);
            view.setTag(holder);
        }else{
            holder=(Holder)view.getTag();
        }

        final BeanCategory bean=data.get(i);
        holder.tv_content.setText(bean.getName());
        ImageUtils.BindImage(context,holder.iv_image, bean.getImage(),1);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, ActivitySearchAllGod.class);
                intent.putExtra("type",bean.getId());
                context.startActivity(intent);
            }
        });
        return view;
    }



    class Holder {
        final private ImageView iv_image;
        final private TextView tv_content;

        public Holder(View root) {
            iv_image=root.findViewById(R.id.iv_image);
            tv_content=root.findViewById(R.id.tv_content);
        }
    }


}
